-- world
-- created by panyl
-- 世界

return {
    apply = function(cardId)
        -- 随机获得一个宝物
        local equips = {};
        local args = TarotM.query(cardId, "args") or {};
        local levelRange = args["level_range"];
        local min, max;

        -- 取得宝物阶位的范围
        local range = string.explode(levelRange, "~");
        if #range > 1 then
            min = tonumber(range[1]);
            max = tonumber(range[2]);
        else
            min = tonumber(range[1]);
            max = min;
        end

        assert(max >= min);

        for _, classId in pairs(table.deepcopy(EquipM.getAllTreasure())) do
            if EquipM.query(classId, "rank") >= min and EquipM.query(classId, "rank") <= max
             and ItemM.query(classId,"type") == ITEM_TYPE_TREASURE then
                table.insert(equips, classId);
            end
        end

        -- 排序
        table.sort(equips);

        local rand = DungeonM.getRandSeed("tarot_world");
        local classId = equips[rand % #equips + 1];

        BonusM.doBonus({1, classId, 1, }, "tarot_bonus");
    end,
};
